
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JFormattedTextField;
import javax.swing.JTextField;
import javax.swing.text.MaskFormatter;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;
import javax.swing.UIManager;


public class SearchPhotoGUI extends JFrame{
	
	private JLabel lblLocation = null;
	private JLabel lblTime = null;
	private JButton btnWorldMap = null;
	private JButton btnSearch = null;
	private JFormattedTextField formattedTxtTime = null;
	private JTextField txtFieldLocation = null;
	private JPanel panel = null;



	public SearchPhotoGUI() {
		getContentPane().setLayout(null);
		getContentPane().add(getLblLocation());
		getContentPane().add(getLblTime());
		getContentPane().add(getBtnWorldMap());
		getContentPane().add(getBtnSearch());
		getContentPane().add(getFormattedTxtTime());
		getContentPane().add(getTxtFieldLocation());
		getContentPane().add(getPanel());
		
		this.setTitle("Search Photo");
		this.setBounds(500, 200, 344, 192);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setVisible(true);
		
	}
	
	
	private JPanel getPanel() {
		if(panel == null){
			panel = new JPanel();
			panel.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Photo Details", TitledBorder.LEADING, TitledBorder.BOTTOM, null, null));
			panel.setBounds(0, 0, 328, 109);
		}
		return panel;
	}
	
	private JTextField getTxtFieldLocation() {
		if(txtFieldLocation == null){
			txtFieldLocation = new JTextField();
			txtFieldLocation.setBounds(176, 31, 138, 20);
			txtFieldLocation.setColumns(10);
		}
		return txtFieldLocation;
	}

	private JFormattedTextField getFormattedTxtTime() {
		if(formattedTxtTime == null){
			formattedTxtTime = new JFormattedTextField(createFormatter("##/##/####"));
			formattedTxtTime.setBounds(10, 31, 138, 20);
		}
		return formattedTxtTime;
	}

	
	private JButton getBtnWorldMap() {
		if(btnWorldMap == null){
			btnWorldMap = new JButton("World Map");
			btnWorldMap.setBounds(176, 62, 138, 23);
		}
		return btnWorldMap;
	}
	
	private JLabel getLblTime() {
		if(lblTime == null){
			lblTime = new JLabel("Time");
			lblTime.setBounds(10, 11, 46, 14);
		}
		return lblTime;
	}
	
	private JLabel getLblLocation() {
		if(lblLocation == null){
			lblLocation = new JLabel("Location");
			lblLocation.setBounds(176, 11, 69, 14);
		}
		return lblLocation;
	}
	
	private JButton getBtnSearch() {
		if(btnSearch == null) {
			btnSearch = new JButton("Search");
			btnSearch.setBounds(10, 120, 89, 23);
		}
		return btnSearch;
	}
	
	// Create a specific format for a specific field
	private MaskFormatter createFormatter(String s) {
			MaskFormatter formatter = null;
			try {
				formatter = new MaskFormatter(s);
			} catch (java.text.ParseException exc) {
				System.err.println("formatter is bad: " + exc.getMessage());
				System.exit(-1);
			}
			return formatter;
		}
}
